package com.zdc.learn.netty.rpc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test {

    private static Lock  lock1 = new ReentrantLock(true);

    public static void main(String[] args) {

        for (int i=0;i<3;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    aa();
                }
            }).start();
        }
    }

   public static void aa(){

       try {
           if (lock1.tryLock()){
               lock1.lock();
           }
           System.out.println(lock1.tryLock());
       }catch (Exception e){
           e.printStackTrace();
       }finally {
           if (!lock1.tryLock()){
               lock1.unlock();
               System.out.println("释放锁");
           }
       }
   }
}
